package ${package.Controller};


import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.beans.factory.annotation.Autowired;
import io.swagger.annotations.Api;
import com.jd.model.Response;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;
import java.util.Arrays;

import ${package.Service}.${table.serviceName};
import ${package.Entity}.${entity};

<#if restControllerStyle>
import org.springframework.web.bind.annotation.RestController;
<#else>
import org.springframework.stereotype.Controller;
</#if>
<#if superControllerClassPackage??>
import ${superControllerClassPackage};
</#if>

/**
 * <p>
 * ${table.comment!} 前端控制器
 * </p>
 *
 * @author ${author}
 * @since ${date}
 */
<#if restControllerStyle>
@RestController
<#else>
@Controller
</#if>
@Api(tags = "${entity}接口管理")
@RequestMapping("<#if package.ModuleName?? && package.ModuleName != "">/${package.ModuleName}</#if>/<#if controllerMappingHyphenStyle??>${controllerMappingHyphen}<#else>${table.entityPath}</#if>")
<#if kotlin>
class ${table.controllerName}<#if superControllerClass??> : ${superControllerClass}()</#if>
<#else>
<#if superControllerClass??>
public class ${table.controllerName} extends ${superControllerClass} {
<#else>
public class ${table.controllerName} {
</#if>

    @Autowired
    public ${table.serviceName} ${table.serviceName?uncap_first};

    @GetMapping()
    @ApiOperation("获取列表")
    public Response list() throws Exception {
        return Response.ok(${table.serviceName?uncap_first}.list());
    }

    @GetMapping("/{key}")
    @ApiOperation("根据key获取")
    public Response getByKey(@PathVariable String key) throws Exception {
        return Response.ok(${table.serviceName?uncap_first}.getById(key));
    }

    @PostMapping
    @ApiOperation("保存")
    public Response save(@RequestBody ${entity} ${entity?uncap_first}) throws Exception {
        boolean b = ${table.serviceName?uncap_first}.save(${entity?uncap_first});
        return b ? Response.ok() : Response.fail();
    }

    @PutMapping
    @ApiOperation("修改")
    public Response update(@RequestBody ${entity} ${entity?uncap_first}) throws Exception {
        boolean b = ${table.serviceName?uncap_first}.updateById(${entity?uncap_first});
        return b ? Response.ok() : Response.fail();
    }

    @DeleteMapping("/{keys}")
    @ApiOperation("根据key值删除")
    public Response deleteByKeys(@PathVariable String[] keys) throws Exception {
        boolean b = ${table.serviceName?uncap_first}.removeByIds(Arrays.asList(keys));
        return b ? Response.ok() : Response.fail();
    }
}
</#if>
